from manimlib import *
from numpy import square
import numpy as np

class Test(Scene):
    #75cfb8
    #浅绿
    #bbdfc8
    #浅黄
    #f0e5d8
    #深黄
    #ffc478
    def construct(self):
        # self.add(NumberPlane())
        for y in range(9,10):
            self.add(Line([-3,0,0],[y/4-3,0.7*y,0],color=BLACK).shift(DOWN*3),Line([+3.75,0,0],[-y/2+3.75,0.7*y,0],color=BLACK).shift(DOWN*3),)

        for y in range(10):
            # self.add(Point([y/4-3,0.7*y,0]).shift(DOWN*3))
            # self.add(Point([-y/2+3.75,0.7*y,0]).shift(DOWN*3))
            self.add(Line([y/4-3,0.7*y,0],[-y/2+3.75,0.7*y,0],color=BLACK).shift(DOWN*3))
            if y <9:
                self.add(DoubleArrow(ORIGIN,[0,0.7,0],color=BLACK,buff=0).shift(DOWN*3+UP*0.7*y+LEFT*4))
        for y in range(8,-1,-1):
            if y==8:
                self.add(Tex('x',color=BLACK).shift(UP*3))
            elif y==7:
                x2=Tex('=',color=BLACK).shift(UP*2.3+RIGHT*0.5)
                x22=Polygon([9/4-3,0.7*9,0],[7/4-3,0.7*7,0],[-7/2+3.75,0.7*7,0],color=BLACK).next_to(x2)
                x222=Tex('-',color=BLACK).next_to(x22)
                x2222=Polygon([9/4-3,0.7*9,0],[8/4-3,0.7*8,0],[-8/2+3.75,0.7*8,0],color=BLACK).next_to(x222)
                self.add(x2,x22,x222,x2222)
            if y%2==0:
                self.add(Polygon([y/4-3,0.7*y,0],[-y/2+3.75,0.7*y,0],[-(y+1)/2+3.75,0.7*(y+1),0],[(y+1)/4-3,0.7*(y+1),0],color=BLACK,fill_opacity=1).set_fill('#75cfb8').shift(DOWN*3))
            else:
                self.add(Polygon([y/4-3,0.7*y,0],[-y/2+3.75,0.7*y,0],[-(y+1)/2+3.75,0.7*(y+1),0],[(y+1)/4-3,0.7*(y+1),0],color=BLACK,fill_opacity=1).set_fill('#ffc478').shift(DOWN*3))
            self.wait(0.03)
        s1=Square(color=BLACK,fill_opacity=1).scale(0.3).set_fill('#75cfb8').move_to(UR*3)
        self.add(s1,Tex('=145',color=BLACK).next_to(s1))
        s2=Square(color=BLACK,fill_opacity=1).scale(0.3).set_fill('#ffc478').next_to(s1,DOWN)
        self.add(s2,Tex(r'=\quad?',color=BLACK).next_to(s2))
        self.wait(0.03)
        # self.wait(1)